home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 30 / Mac Magazin and MacEasy Magazine CD - Issue 30.iso / utilities / Mac OS X / Flurry / Flurry source / Source Folder / Spark.cpp < prev    next >
C/C++ Source or Header  |  2002-01-25  |  5KB  |  192 lines

  1. // Spark.cpp: implementation of the Spark class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4.  
  5. #include "std.h"
  6. #include "Spark.h"
  7.  
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11.  
  12. Spark::Spark()
  13. {
  14.  
  15. }
  16.  
  17. Spark::~Spark()
  18. {
  19.  
  20. }
  21.  
  22. void Spark::Draw()
  23. {
  24.     return;
  25.     float width,sx,sy;
  26.     float w,z;
  27.     width = 60000.0f * sys_glWidth / 1024.0f;
  28.     
  29.     z = position[2];
  30.     sx = position[0] * sys_glWidth / z + sys_glWidth * 0.5f;
  31.     sy = position[1] * sys_glWidth / z + sys_glHeight * 0.5f;
  32.     w = width*4.0f / z;
  33.     
  34.     float screenx = sx;
  35.     float screeny = sy;
  36.     
  37.     const float black[4] = {0.0f,0.0f,0.0f,1.0f};
  38.     
  39.     glPushMatrix();
  40.     glTranslatef(screenx,screeny,0.0f);
  41.     float scale = w/50.0f;
  42.     glScalef(scale,scale,0.0f);
  43.     float a;
  44.     float c = 0.0625f;
  45.     for (int k=0;k<12;k++)
  46.     {
  47.         a = ((float) (rand() % 3600)) / 10.0f;
  48.         glRotatef(a,0.0f,0.0f,1.0f);
  49.         glBegin(GL_QUAD_STRIP);
  50.         glColor4fv(black);
  51.         glVertex2f(-3.0f,0.0f);
  52.         a = 2.0f + (float) (rand() & 255) * c;
  53.         glVertex2f(-3.0f,a);
  54.         glColor4fv(color);
  55.         glVertex2f(0.0f,0.0f);
  56.         glColor4fv(black);
  57.         glVertex2f(0.0f,a);
  58.         glVertex2f(3.0f,0.0f);
  59.         glVertex2f(3.0f,a);
  60.         glEnd();
  61.     }
  62.     glPopMatrix();
  63. }
  64.  
  65. #define BIGMYSTERY 1800.0
  66. #define MAXANGLES 16384
  67.  
  68. void Spark::Update()
  69. {
  70. //    const float rotationsPerSecond = (float) (2.0*PI*TICKSPERSECOND/MAXANGLES);
  71.     const float rotationsPerSecond = (float) (2.0*PI*fieldSpeed/MAXANGLES);
  72.     double thisPointInRadians;
  73.     double thisAngle = fTime*rotationsPerSecond;
  74.     float cf;
  75.     int i;
  76.     double tmpX1,tmpY1,tmpZ1;
  77.     double tmpX2,tmpY2,tmpZ2;
  78.     double tmpX3,tmpY3,tmpZ3;
  79.     double tmpX4,tmpY4,tmpZ4;
  80.     double rotation;
  81.     double cr;
  82.     double sr;
  83.     float cycleTime = 20.0f;
  84.  
  85.     if (currentColorMode == rainbowColorMode)
  86.     {
  87.         cycleTime = 1.5f;
  88.     }
  89.     else if (currentColorMode == tiedyeColorMode)
  90.     {
  91.         cycleTime = 4.5f;
  92.     }
  93.     else if (currentColorMode == cyclicColorMode)
  94.     {
  95.         cycleTime = 20.0f;
  96.     }
  97.     else if (currentColorMode == slowCyclicColorMode)
  98.     {
  99.         cycleTime = 120.0f;
  100.     }
  101.     float colorRot = (float) (2.0*PI/cycleTime);
  102.     float redPhaseShift = 0.0f; //cycleTime * 0.0f / 3.0f 
  103.     float greenPhaseShift = cycleTime / 3.0f; 
  104.     float bluePhaseShift = cycleTime * 2.0f / 3.0f ;
  105.     float baseRed;
  106.     float baseGreen;
  107.     float baseBlue;
  108.     float colorTime = fTime;
  109.     if (currentColorMode == whiteColorMode)
  110.     {
  111.         baseRed = 0.1875f;
  112.         baseGreen = 0.1875f;
  113.         baseBlue = 0.1875f;
  114.     }
  115.     else if (currentColorMode == multiColorMode)
  116.     {
  117.         baseRed = 0.0625f;
  118.         baseGreen = 0.0625f;
  119.         baseBlue = 0.0625f;
  120.     }
  121.     else if (currentColorMode == darkColorMode)
  122.     {
  123.         baseRed = 0.0f;
  124.         baseGreen = 0.0f;
  125.         baseBlue = 0.0f;
  126.     }
  127.     else
  128.     {
  129.         if (currentColorMode < slowCyclicColorMode)
  130.         {
  131.             colorTime = (currentColorMode / 6.0f) * cycleTime;
  132.         }
  133.         else
  134.         {
  135.             colorTime = fTime;
  136.         }
  137.         baseRed = 0.109375f * ((float) cos((colorTime+redPhaseShift)*colorRot)+1.0f);
  138.         baseGreen = 0.109375f * ((float) cos((colorTime+greenPhaseShift)*colorRot)+1.0f);
  139.         baseBlue = 0.109375f * ((float) cos((colorTime+bluePhaseShift)*colorRot)+1.0f);
  140.     }
  141.  
  142.     float old[3];
  143.     
  144.     for (i=0;i<3;i++)
  145.     {
  146.         old[i] = position[i];
  147.     }
  148.     
  149.     cf = ((float) (cos(7.0*((fTime)*rotationsPerSecond))+cos(3.0*((fTime)*rotationsPerSecond))+cos(13.0*((fTime)*rotationsPerSecond))));
  150.     cf /= 6.0f;
  151.     cf += 2.0f;
  152.     thisPointInRadians = 2.0 * PI * (double) mystery / (double) BIGMYSTERY;
  153.     
  154.     color[0] = baseRed + 0.0625f * (0.5f + (float) cos((15.0 * (thisPointInRadians + 3.0*thisAngle))) + (float) sin((7.0 * (thisPointInRadians + thisAngle))));
  155.     color[1] = baseGreen + 0.0625f * (0.5f + (float) sin(((thisPointInRadians) + thisAngle)));
  156.     color[2] = baseBlue + 0.0625f * (0.5f + (float) cos((37.0 * (thisPointInRadians + thisAngle))));
  157.     position[0] = fieldRange * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
  158.     position[1] = fieldRange * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
  159.     position[2] = fieldRange * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle))));
  160.     
  161.     rotation = thisAngle*0.501 + 5.01 * (double) mystery / (double) BIGMYSTERY;
  162.     cr = cos(rotation);
  163.     sr = sin(rotation);
  164.     tmpX1 = position[0] * cr - position[1] * sr;
  165.     tmpY1 = position[1] * cr + position[0] * sr;
  166.     tmpZ1 = position[2];
  167.     
  168.     tmpX2 = tmpX1 * cr - tmpZ1 * sr;
  169.     tmpY2 = tmpY1;
  170.     tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
  171.     
  172.     tmpX3 = tmpX2;
  173.     tmpY3 = tmpY2 * cr - tmpZ2 * sr;
  174.     tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
  175.     
  176.     rotation = thisAngle*2.501 + 85.01 * (double) mystery / (double) BIGMYSTERY;
  177.     cr = cos(rotation);
  178.     sr = sin(rotation);
  179.     tmpX4 = tmpX3 * cr - tmpY3 * sr;
  180.     tmpY4 = tmpY3 * cr + tmpX3 * sr;
  181.     tmpZ4 = tmpZ3;
  182.     
  183.     position[0] = (float) tmpX4 + RandBell(5.0f*fieldCoherence);
  184.     position[1] = (float) tmpY4 + RandBell(5.0f*fieldCoherence);
  185.     position[2] = (float) tmpZ4 + RandBell(5.0f*fieldCoherence);
  186.  
  187.     for (i=0;i<3;i++)
  188.     {
  189.         delta[i] = (position[i] - old[i])/fDeltaTime;
  190.     }
  191. }
  192.